package com.jiyun.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.jiyun.pojo.Integrate;
import com.jiyun.pojo.JsonRes;
import com.jiyun.service.IntegrateService;
import com.jiyun.utils.AliyunOSSClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author: 刘清芳
 * @description: 积分商品
 * @date: 2024/1/3 20:29
 */
@RestController
@RequestMapping("integrate")
public class IntegrateController {
    @Autowired
    IntegrateService integralService;
    @GetMapping("findAll")
    public IPage<Integrate> findAll(Integer pageNum,Integer pageSize,Integrate integrate){
        return integralService.findAll(pageNum,pageSize,integrate);
    }
//    添加
    @PostMapping("/add")
    public void add(@RequestBody Integrate integrate){
        integralService.findAdd(integrate);
    }
    //    上传图片
    @PostMapping("/fileUpload")
    public JsonRes fileUpload(MultipartFile file) {
        AliyunOSSClientUtil aliyunOSSClientUtil = new AliyunOSSClientUtil();
        try {
            String s = aliyunOSSClientUtil.uploadImg2Oss(file);
            String imgUrl = aliyunOSSClientUtil.getImgUrl(s);
            return JsonRes.success(imgUrl);
        } catch (Exception e) {
            e.printStackTrace();
            return JsonRes.error("上传失败");
        }
    }
}
